﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UI;
using UnityEngine.UI;
using Yunchang.NetworkLayer;
using ProtoBuf.Message;
using Yunchang;

public class ChessWinEffect : MonoBehaviour
{
    [SerializeField]
    private Text BonusToVictory;
    [SerializeField]
    private GameObject BonusRoot;
    private void Awake()
    {
        NetworkDriver.Instance.RegistSocketHandler(OpDefine.SCAutoChessGetFightSettle, SetBonusToVictory);
        NetworkDriver.Instance.SendSocketBlock(OpDefine.CSAutoChessGetFightSettle, new CSAutoChessGetFightSettle(), OpDefine.SCAutoChessGetFightSettle);

    }

    private void OnDestroy()
    {
        NetworkDriver.Instance.UnregisterSocketHandler(OpDefine.SCAutoChessGetFightSettle, SetBonusToVictory);
    }


    private void SetBonusToVictory(object msg)
    {
        var fightSettle = msg as SCAutoChessGetFightSettle;
        if (fightSettle.gold > 0)
        {
            BonusRoot.SetActiveEx(true);
            BonusToVictory.text = "+" + fightSettle.gold.ToString();
            EventManager.TriggerEvent(CommonEvent.ON_PlayEffect_Meteor);
        }
        else
        {
            BonusRoot.SetActiveEx(false);
        }
    }
}
